package yja.gzw.app.activity

import android.content.Intent
import android.util.Log
import android.widget.Toast
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import yja.gzw.app.R
import yja.gzw.app.adapter.FabuddAdapter
import yja.gzw.app.adapter.Fabudingdan2Adapter
import yja.gzw.app.base.BaseActivity
import yja.gzw.app.databinding.ActivityFabidingdanBinding
import yja.gzw.app.fragmentview.FabudingdanFaragment
import yja.gzw.app.fragmentview.HomeFragment
import yja.gzw.app.fragmentview.WodeFragment
import yja.gzw.app.fragmentview.XiaoxiFragment
import yja.gzw.app.model.UserData
import yja.gzw.app.viewmodel.Mainviewmodel
import com.google.android.material.tabs.TabLayout
import yja.gzw.app.adapter.Fabudingdan2Adapter2
import yja.gzw.app.fragmentview.DindanerFragment
import yja.gzw.app.fragmentview.DindanliuFragment
import yja.gzw.app.fragmentview.DindanqiFragment
import yja.gzw.app.fragmentview.DindansanFragment
import yja.gzw.app.fragmentview.DindansiFragment
import yja.gzw.app.fragmentview.DindanwuFragment
import yja.gzw.app.fragmentview.DindanyiFragment

class FabidingdanActivity :BaseActivity<Mainviewmodel, ActivityFabidingdanBinding>(R.layout.activity_fabidingdan){
    private lateinit var fabiada: Fabudingdan2Adapter
    private lateinit var fabiada2: Fabudingdan2Adapter2
    val list_title= mutableListOf<String>("全部","发布中","待确认","待发货","待收货","待评价","撤销订单")

    val listfragment= mutableListOf<Fragment>(
        DindanyiFragment(), DindanerFragment(), DindansanFragment(),
        DindansiFragment(), DindanwuFragment(), DindanliuFragment(), DindanqiFragment()
    )


    override fun initView() {
        binding.fanhui.setOnClickListener {
            finish()
        }

        binding.sousuo.setOnClickListener {
            val intent= Intent(this, SousoudingActivity::class.java)
            startActivity(intent)
        }




//        for (i in 0  until list_title.size ){
//            val tab = binding.tabss.newTab()
//            binding.tabss.addTab(tab.setText(list_title[i]))
//        }

        binding.viewpager.adapter=object : FragmentPagerAdapter(supportFragmentManager){
            override fun getCount(): Int {

                return listfragment.size

            }

            override fun getItem(position: Int): Fragment {

                return listfragment[position]

            }

            override fun getPageTitle(position: Int): CharSequence {
                return list_title[position]
            }

        }

        binding.tabss.setupWithViewPager(binding.viewpager)

       // viewmodel.onfabu2shwowang(UserData.token, mapOf("keyword" to "","status" to "all","page" to "1","pagesize" to "10"))
   binding.tabss.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
       override fun onTabSelected(tab: TabLayout.Tab) {
//            if(tab.position==0){
//                viewmodel.onfabu2shwowang(UserData.token, mapOf("keyword" to "","status" to "all","page" to "1","pagesize" to "10"))
//
//            }else if(tab.position==1){
//                viewmodel.onfabu2shwowang(UserData.token, mapOf("keyword" to "","status" to "1","page" to "1","pagesize" to "10"))
//
//
//            }else if(tab.position==2){
//                viewmodel.onfabu2shwowang2(UserData.token, mapOf("keyword" to "","status" to "2","page" to "1","pagesize" to "10"))
//
//
//            }else if(tab.position==3){
//                viewmodel.onfabu2shwowang2(UserData.token, mapOf("keyword" to "","status" to "3","page" to "1","pagesize" to "10"))
//
//
//            }else if(tab.position==4){
//                viewmodel.onfabu2shwowang2(UserData.token, mapOf("keyword" to "","status" to "4","page" to "1","pagesize" to "10"))
//
//
//            }else  if(tab.position==5){
//                viewmodel.onfabu2shwowang2(UserData.token, mapOf("keyword" to "","status" to "5","page" to "1","pagesize" to "10"))
//
//            }else  if(tab.position==6){
//                viewmodel.onfabu2shwowang2(UserData.token, mapOf("keyword" to "","status" to "-1","page" to "1","pagesize" to "10"))
//
//
//            }


       }

       override fun onTabUnselected(tab: TabLayout.Tab?) {

       }

       override fun onTabReselected(tab: TabLayout.Tab?) {

       }
   })






    }

    override fun dataObservese() {

//        viewmodel.onfabu2shwo.observe(this, Observer {
//            if(it.code==1){
//                  Log.e("订单请求的数据","走到了")
//                Log.e("订单请求的数据",it.data.data.toString())
//                binding.recview.layoutManager=
//                    LinearLayoutManager(this)
//                fabiada= Fabudingdan2Adapter(this,it.data.data)
//                binding.recview.adapter= fabiada
//
//            }else{
//
//                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
//            }
//
//
//        })
//
//        viewmodel.onfabu2shwo2.observe(this, Observer {
//            if(it.code==1){
//                Log.e("订单请求的数据","走到了2")
//                Log.e("订单请求的数据",it.data.data.toString())
//                binding.recview.layoutManager=
//                    LinearLayoutManager(this)
//                fabiada2= Fabudingdan2Adapter2(this,it.data.data)
//                binding.recview.adapter= fabiada2
//
//            }else{
//
//                Toast.makeText(this,it.msg, Toast.LENGTH_SHORT).show()
//            }
//
//
//        })
    }
}